package com.xz.realdemo.util;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

/**
 * @author 张志航     
 * @version V1.0.0
 * @projectName design_mode
 * @title     XMLUtil   
 * @package    com.xz.realdemo.util  
 * @date   2019/11/24 17:52  
 * @explain
 */
public class XMLUtil {

    // 该方法用于从图标类中获取配置的类型名
    public static String getChartType(){
        try {
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = dFactory.newDocumentBuilder();
            Document doc = documentBuilder.parse(new File("SimpleFactory/src/com/xz/realdemo/config.xml"));

            // 获取包含图表配置的文本
            NodeList chartType = doc.getElementsByTagName("chartType");
            Node classNode = chartType.item(0).getFirstChild();
            String chart = classNode.getNodeValue().trim();
            return chart;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
